import { defineStore } from "pinia";
import { store } from "@/store";
import type { appToken, userInfo } from "@/types/app"
import { getUsetInfo } from "@/api/user-app";
interface app extends userInfo, appToken {

}
const appStore = defineStore({
    id: "app",
    state: (): app => ({
        token: "",
        account: "",
        address: "",
        auth: 0,
        nick_name: "",
        phone: "",
        sex: "",
        shops: "",
        update_time: "",
        uuid: ""
    }),
    actions: {
        setToken(token: string) {
            this.token = token
            this.getUserInfo()
        },
        async getUserInfo() {
            const res = await getUsetInfo<userInfo>()
            console.log(this)
            this.account = res.account,
                this.address = res.address,
                this.auth = res.auth,
                this.nick_name = res.nick_name,
                this.phone = res.phone,
                this.sex = res.sex,
                this.shops = res.shops,
                this.update_time = res.update_time,
                this.uuid = res.uuid
        }
    },
    getters: {
        getToken() {
            return this.token
        },
        getSlefUsetInfo(): userInfo {
            return {
                account: this.account,
                address: this.address,
                auth: this.auth,
                nick_name: this.nick_name,
                phone: this.phone,
                sex: this.sex,
                shops: this.shops,
                update_time: this.update_time,
                uuid: this.uuid
            }
        }

    }
})
export function useAppStoreWithOut() {
    return appStore(store);
}